var pokerSprites = [];

cc.Class({
    extends: cc.Component,

    properties: {
        Atlas: {
            default: null,
            type: cc.SpriteAtlas
        },
        _sides: null,
        _pres: null,
        _foldPres: null,
    },

    onLoad: function () {
        if (cc.vv == null) {
            return;
        }

        cc.vv.pokerMgr = this;
        var type = ["ht_", "hx_", "mh_", "fk_"];
        pokerSprites.push("beijing");
        //方块
        for (var i = 1; i < 14; ++i) {
            pokerSprites.push("fk_" + i);
        }

        //梅花
        for (var i = 1; i < 14; ++i) {
            pokerSprites.push("mh_" + i);
        }

        //红心
        for (var i = 1; i < 14; ++i) {
            pokerSprites.push("hx_" + i);
        }

        //黑桃
        for (var i = 1; i < 14; ++i) {
            pokerSprites.push("ht_" + i);
        }

        //大小王
        pokerSprites.push("xiaowang");
        pokerSprites.push("dawang");

        for (var i = 0; i < 55; ++i) {
            pokerSprites.push(pokerSprites[i + 1]);
        }
    },

    getpokerSpriteByID: function (id) {
        return pokerSprites[id];
    },

    getSpriteFrameByPKID: function (NNjson) {
        return this.Atlas.getSpriteFrame(this.getpokerSpriteByID(NNjson));
    },

    getSpriteFrameByBG: function (bg) {
        return this.xzbgAtlas.getSpriteFrame(bg);
    },

    getSpriteFrameByPD: function (pd) {
        var returndian = '';
        if (cc.vv.gameNetMgr.conf.type == 'nn') {
            var nn = {
                '0': '没牛',
                '1': '牛一',
                '2': '牛二',
                '3': '牛三',
                '4': '牛四',
                '5': '牛五',
                '6': '牛六',
                '7': '牛七',
                '8': '牛八',
                '9': '牛九',
                '10': '牛牛',
                '11': '金花',
            }
            for (var i in nn) {
                if (parseFloat(i) == pd) {
                    returndian = nn[i]
                }
            }
        } else {
            var jdb = {
                '0': '没点',
                '1': '一点',
                '2': '两点',
                '3': '三点',
                '4': '四点',
                '5': '五点',
                '6': '六点',
                '7': '七点',
                '8': '八点',
                '9': '九点',
                '0.5': '十点半',
                '1.5': '一点半',
                '2.5': '二点半',
                '3.5': '三点半',
                '4.5': '四点半',
                '5.5': '五点半',
                '6.5': '六点半',
                '7.5': '七点半',
                '8.5': '八点半',
                '9.5': '九点半',
                '9.2': '对子',
            }
            for (var i in jdb) {
                if (parseFloat(i) == pd) {
                    returndian = jdb[i]
                }
            }
        }
        return returndian;
    },
    getSpriteFrameByZHU: function (pd) {
        return this.zhuAtlas.getSpriteFrame(pd);
    },
    //音频    
    getAudioURLByNNID: function (pd) {
        var sex = cc.vv.userMgr.sex == 1 ? 'nan' : 'nv';
        if (cc.vv.gameNetMgr.conf.type == 'nn') {
            return sex + "/nn/n" + pd + ".ogg";
        } else {
            if (Math.floor(pd) == pd) {
                pd = pd + '_0';
            } else {
                pd = (pd + "").replace('.', '_');
            }
            return sex + "/jdb/" + pd + ".mp3";
        }

    },

    sortNN: function (nns) {
        var self = this;
        var newNns = nns;
        for (var i = 0; i < nns.length; ++i) {
            if (nns[i] == 53) {
                newNns.push(13);
            } else if (nns[i] == 54) {
                newNns.push(14);
            } else {
                newNns.push(nns[i] % 13 == 0 ? 13 : nns[i] % 13);
            }
        }

        newNns.sort(function (a, b) {
            return a - b;
        });
    },

    getSide: function (localIndex) {
        return this._sides[localIndex];
    },

    getPre: function (localIndex) {
        return this._pres[localIndex];
    },

    getFoldPre: function (localIndex) {
        return this._foldPres[localIndex];
    }
});


